import axios from 'axios'
import qs from 'qs'
axios.defaults.withCredentials = false;
const baseURL = 'http://localhost:3000';
export default {
  login: (data) =>{
      return axios.post(`${baseURL}/user/login`,data).then(res=>{
        return res.data
      })
  },
  //根据班级guid获取签到
  getSignListByClassGuid:(classGuid)=>{
    return axios.get(`${baseURL}/sign/class?classGuid=${classGuid}`).then(res=>{
      return res.data
    })
},
  //根据创建者id获取签到
  getSignListByCreater:(creater=>{
    return axios.get(`${baseURL}/sign/create?creater=${creater}`).then(res=>{
      return res.data;
    })
  }),
  //删除指定签到
  deleteSignById:(id=>{
    return axios.delete(`${baseURL}/sign?sign_id=${id}`).then(res=>{
     return res.data;
    })
  }),
  //导出签到表格
  exportExcelById:(id=>{
    window.open(`${baseURL}/sign/excel?sign_id=${id}`, "_blank");//打开一个新的窗口，调用下载的API
    }),
  //签到
  sign:(data=>{
    return axios.post(`${baseURL}/sign/student`,data).then(res=>{
      return res.data;
    })
  }),
// 获取班级列表
  getClassList:()=>{
     return axios.get(`${baseURL}/class`).then(res=>{
       return res.data;
     })
  },
// 获取密保问题列表
  getProblemList:()=>{
    return axios.get(`${baseURL}/user/problem`).then(res=>{
      return res.data;
    })
  },
 //用户注册
 register:(data=>{
   return axios.post(`${baseURL}/user/register`,data).then(res=>{
     return res.data
   })
 }),
  //创建签到
  addSign:(data=>{
    return axios.post(`${baseURL}/sign/add`,data).then(res=>{
      return res.data;
    })
  }),
  //根据创建者获取班级列表
  getClassListByCreater:(id=>{
    return axios.get(`${baseURL}/class/classList?user_number=${id}&status=1`).then(res=>{
      return res.data;
    })
}),
  //创建班级
  addClass:(data=>{
    return axios.post(`${baseURL}/class/add`,data).then(res=>{
      return res.data;
    })
  }),
  //根据班级Id删除班级
  deleteClass:(id=>{
    return axios.put(`${baseURL}/class?classId=${id}`).then(res=>{
      return res.data;
    })
  }),
  //根据班级ID来修改班级
  updateClass:(data=>{
    return axios.post(`${baseURL}/class/modify`,data).then(res=>{
      return res.data;
    })
  }),
  //根据签到ID获取指定签到
  getSignByID:(id=>{
    return axios.get(`${baseURL}/sign?signGuid=${id}`).then(res=>{
      return res.data;
    })
  }),
  //找回密码
  getPsd:(data=>{
    return axios.post(`${baseURL}//user/find`,data).then(res=>{
      return res.data;
    })
  })
}
